package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import com.example.fw.ContactObject;
import com.example.fw.Contacts;

public class ContactCreationTests extends TestBase {

	@Test(dataProvider = "ContactObjectFromFile", dataProviderClass = ContactDataGenerator.class)
	public void newContactWithAllData(ContactObject validContact) throws Exception {
		Contacts oldList = app.getContactHelper().getContacts();
		app.getContactHelper().createContact(validContact);
		Contacts newList = app.getContactHelper().getContacts();
		assertThat(newList, equalTo(oldList.withAdded(validContact)));
	} 	

	@Test
	public void testUiAndDbConformsWithModel(){
		if (app.getProperty("ui.check") != null) {
			Contacts modelList = app.getHibernateHelper().getContacts();
			Contacts DbList = app.getHibernateHelper().getContacts();
			Contacts UiList = app.getContactHelper().getUIContacts();
			log.info("UiList: " + UiList);
			assertThat(DbList, equalTo(UiList));
			assertThat(DbList, equalTo(modelList));		
		}
	}
	
	@Test
	public void newContactWithEmptyData() throws Exception {
		ContactObject emptyContact = new ContactObject()
		.setFirstname("")
		.setLastname("")
		.setAddress("")
		.setHome("")
		.setMobile("")
		.setWork("")
		.setEmail("")
		.setEmail2("")
		.setYear("")
		.setAddress2("")
		.setPhone2("")
		.setDay("-")
		.setMonth("-")
		.setGroupName(0);	
		app.getContactHelper().createContact(emptyContact);
	}
}
